{include file="common/header"/}
<div class="LM-container">
    <div class="LM-main">
        <fieldset class="layui-elem-field layui-field-title">
            <legend>{:lang('addons')}{:lang('list')}</legend>
            <blockquote class="layui-elem-quote">

                <div class="LM-table">
                    <div class="layui-inline">
                        <input type="text" id='keys' name="keys" lay-verify="required" placeholder="{:lang('pleaseEnter')}" autocomplete="off" class="layui-input">
                    </div>
                    <a href="javascript:;" class="layui-btn data-add-btn layui-btn-sm" lay-submit="" lay-filter="add" id="search">{:lang('search')}</a>
<!--                    <a href="{:url('add')}"  class="layui-btn layui-btn-sm layui-btn-warm">{:lang('add')}{:lang('ad')}</a>-->

                </div>

            </blockquote>

        </fieldset>

        <table class="layui-table layui-hide" id="list" lay-filter="list"></table>
    </div>
</div>


<script type="text/html" id="action">
    {{# if(d.install==1){ }}
    <a href="javascript:;" class="layui-btn  layui-btn-xs" lay-event="config">{:lang('config')}</a>
    <a href="javascript:;" class="layui-btn layui-btn-danger layui-btn-xs" lay-event="uninstall">{:lang('uninstall')}</a>

    {{# }else{ }}

        <a href="javascript:;" class="layui-btn layui-btn-danger layui-btn-xs" lay-event="install">{:lang('install')}</a>
        {{# if(d.demourl !=''){ }}
        <a  href="{{d.demourl}}"  target="_blank" class="layui-btn  layui-btn-xs">{:lang('demo')}</a>
        {{# } }}
    {{# } }}
</script>
<script type="text/html" id="status">
    <input type="checkbox" name="status" value="{{d.name}}" lay-skin="switch" lay-text="启用|关闭" lay-filter="status" {{ d.status == 1 ? 'checked' : '' }}>
</script>

<script type="text/html" id="image">
    {{d.ad_name}}<img src="/static/admin/images/image.gif" onmouseover="layer.tips('<img src={{d.ad_image}}>',this,{tips: [1, '#fff']});" onmouseout="layer.closeAll();">
</script>
<script type="text/html" id="create_time">
    {{layui.util.toDateString(d.create_time*1000, 'yyyy-MM-dd HH:mm:ss')}}
</script>
<script type="text/html" id="update_time">
    {{layui.util.toDateString(d.update_time*1000, 'yyyy-MM-dd HH:mm:ss')}}
</script>

{include file="common/footer"/}
<script>
    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;

        var tableIn = table.render({
            elem: '#list',
            url: '{:url("index")}',
            method: 'post',
            cols: [[
                {checkbox: true, fixed: true},
                {field: 'title', title: '名称', width: 120,sort:true,},
                {field: 'name', title: '标识', width: 100,sort:true,},
                {field: 'describe', title: '描述', width: 220, sort:true,},
                {field: 'version', title: '插件版本', width: 150,sort:true,},
                {field: 'require', title: '适用版本', width: 150,sort:true},
                {field: 'author', title: '作者', width: 150,sort:true},
                {field: 'status', title: '状态', width: 150,sort:true, templet:'#status'},
                // {field: 'create_time', title: '添加时间', width: 180,templet:'#create_time'},
                // {field: 'update_time', title: '修改时间', width: 180,templet:'#update_time'},
                {title:'操作',minWidth:120, toolbar: '#action',align:"center"}

            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 15,
            page: true
        });



        table.on('tool(list)', function(obj){
            var data = obj.data;
            if(obj.event === 'del'){
                layer.confirm('{:lang("Are you sure you want to delete it")}', function(index){
                    loading =layer.load(1, {shade: [0.1,'#fff']});
                    $.post("{:url('groupDel')}",{id:data.id},function(res){
                        layer.close(loading);
                        layer.close(index);
                        if(res.code>0){
                            layer.msg(res.msg,{time:1000,icon:1});
                            obj.del();
                        }else{
                            layer.msg(res.msg,{time:1000,icon:2});
                        }
                    });
                });
            }

        });

        form.on('switch(status)', function(data){

            loading =layer.load(1, {shade: [0.1,'#fff']});
            console.log(data)
            $.post("{:url('state')}",{name:data.value},function(res){
                layer.close(loading);
                if(res.code>0){
                    layer.msg(res.msg,{time:1000,icon:1});
                }else{
                    layer.msg(res.msg,{time:1000,icon:2});
                }
            });
        });

        $('#search').click(function () {
            var $keys = $('#keys').val();
            if(!$keys){
                return layer.msg('请输入关键词');
            }

            tableIn.reload({ page: {page: 1},where: {keys: $keys}});

        })


    });


</script>